#include "thread_pool.h"

void *eaat(void *arg)
{
	printf("当前线程%ld\n",pthread_self());
    int num = *(int *)arg;
    printf("吃饭%d分钟\n",num);
	while(num > 0)
	{
		printf("吃饭中.......%d\n",num);
		sleep(1);
		num--;
	}
	printf("吃饭结束\n");
	return NULL;
}

void *go_fish(void *arg)
{
	printf("当前线程%ld\n",pthread_self());
    int num = *(int *)arg;
    printf("钓鱼%d分钟\n",num);
	while(num > 0)
	{
		printf("钓鱼中.......%d\n",num);
		sleep(1);
		num--;
	}
	printf("钓鱼结束\n");
	return NULL;
}

void *go_sleep(void *arg)
{
	printf("当前线程%ld\n",pthread_self());
    int num = *(int *)arg;
    printf("睡觉%d分钟\n",num);
	while(num > 0)
	{
		printf("睡觉中.......%d\n",num);
		sleep(1);
		num--;
	}
	printf("起床了\n");
	return NULL;
}

int main(void)
{
	thread_pool *pool;
	init_pool(pool,20);

	while(1)
	{
	    printf("1.吃饭  2.钓鱼  3.睡觉\n");
		int choice;
		scanf("%d",&choice);
		if(choice == 1)
		{
			int num = 20;
		    add_task(pool,eaat,&num);
			sleep(1);
		}
		else if(choice == 2)
		{
			int num = 15;
			add_task(pool,go_fish,&num);
			sleep(1);
		}
		else if(choice == 3)
		{
			int num = 30;
			add_task(pool,go_sleep,&num);
			sleep(1);
		}
		else
		{
			printf("输入错误\n");
		}
	}

	destroy_pool(pool);
	return 0;
}
